package operation;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-14
 * Time: 14:00
 */
public class DeleteOperation implements Operation{
    @Override
    public void work(BookList booklist) {
        System.out.println("删除书籍");
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要删除书籍的名称：");
        String name = scan.nextLine();
        int cursize = booklist.getBooksize();
        int i = 0;
        for (; i < cursize; i++) {
            if( booklist.getBooks(i).getName().equals(name)) {
                break;
            }
        }
        if(i == cursize) {
            System.out.println("要删除的书籍不存在");
            return ;
        }
        for (int j = i; j < cursize-1; j++) {
            booklist.setBooks(j,booklist.getBooks(j+1));
        }
        booklist.setBooksize(cursize-1);
        System.out.println("删除成功！");
    }
}
